package com.tc.converter;

import ma.glasnost.orika.converter.BidirectionalConverter;
import ma.glasnost.orika.metadata.Type;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * Created by cai.tian on 2017/10/24.
 * 自定义转换器
 */
@Component
public class OrikaLongToBigDecConverter extends BidirectionalConverter<Long, BigDecimal> {
    @Override
    public BigDecimal convertTo(Long source, Type<BigDecimal> destinationType) {
        return new BigDecimal(source).divide(new BigDecimal(100));
    }

    @Override
    public Long convertFrom(BigDecimal source, Type<Long> destinationType) {
        return source.multiply(new BigDecimal(100)).longValue();
    }
}
